home *** CD-ROM | disk | FTP | other *** search
/ The Essential Home & Business Collection / The Essential Home & Business Collection.iso / 27 / 3 / 5 / HP22D5.ZIP / EXTERN / BARCHART.C < prev    next >
Text File  |  1991-04-16  |  3KB  |  122 lines

  1. #include <stdarg.h>
  2. #include <graph.h>
  3.  
  4. #include "extern.h"
  5.  
  6. #define TOPMARGIN              30
  7. #define BOTTOMMARGIN            30
  8. #define LEFTMARGIN                 120
  9. #define RIGHTMARGIN                120
  10.  
  11. extern savemouse();
  12. extern restoremouse();
  13. extern hide();
  14. extern show();
  15. extern button();
  16.  
  17. pascal near barchart(bars,numbars)
  18.  
  19. int *bars;
  20. int numbars;
  21.  
  22. {
  23.     int highest;
  24.     int i,width,startx,height,maxheight;
  25.     int between;
  26.     struct videoconfig config;
  27.  
  28.     _setvideomode(_HRESBW);
  29.     _getvideoconfig(&config);
  30.  
  31.     for (i=highest=0;i<numbars;i++) {
  32.         if (bars[i] > highest) highest = bars[i];
  33.     }
  34.  
  35.     between = 24 - numbars;
  36.  
  37.     width = (config.numxpixels - (LEFTMARGIN + RIGHTMARGIN) - ((numbars - 1) * between)) / numbars;
  38.  
  39.     startx = LEFTMARGIN;
  40.     maxheight = config.numypixels - (TOPMARGIN + BOTTOMMARGIN);
  41.  
  42.     _moveto(LEFTMARGIN - (between >> 1),config.numypixels - BOTTOMMARGIN);
  43.     _lineto(config.numxpixels - RIGHTMARGIN + (between >> 1),config.numypixels - BOTTOMMARGIN);
  44.  
  45.     for (i=0;i<numbars;i++) {
  46.         height = (maxheight * bars[i]) / highest;
  47.         _rectangle(_GFILLINTERIOR,
  48.             startx,
  49.             (config.numypixels - TOPMARGIN) - height,
  50.             startx + width,
  51.             config.numypixels - BOTTOMMARGIN);
  52.  
  53.         if (i < numbars - 1) {
  54.         _moveto(startx + width + (between >> 1),config.numypixels - BOTTOMMARGIN - 1);
  55.         _lineto(startx + width + (between >> 1),config.numypixels - BOTTOMMARGIN + 1);
  56.         }
  57.  
  58.         startx += width + between;
  59.     }
  60.  
  61. }
  62.  
  63. #define MAXBARS        20
  64. int bars[MAXBARS];
  65.  
  66. Bar(int NumArgs,HANDLE hNumbers,HANDLE hEndTime)
  67.  
  68. {
  69.     int numbars;
  70.     PTR p,s;
  71.     char c;
  72.     SHAREDPTR pShared;
  73.     PACKETPTR Screen;
  74.     MSG msg;
  75.     DWORD endtime;
  76.  
  77.     if (NumArgs < 1 || NumArgs > 2) return(STOP);
  78.  
  79.     numbars = 0;
  80.     p = deref(hNumbers);
  81.     while (*p && numbars <= MAXBARS) {
  82.         for (s=p;*p && *p != ',' && *p != '\r';p++);
  83.         c = *p;
  84.         *p = '\0';
  85.         bars[numbars++] = atoi(s);
  86.         *p = c;
  87.         if (*p) p++;
  88.     }
  89.  
  90.     pShared = GetSharedArea();
  91.     Screen = pShared -> pVideoModes[0];
  92.  
  93.     savemouse();
  94.  
  95.     barchart(bars,numbars);
  96.  
  97.     endtime = (NumArgs == 2) ? GetTime() + (htoi(hEndTime) / 55) : 0;
  98.  
  99.     show();
  100.     do {
  101.         GetEvent(&msg);
  102.     if (endtime) if (GetTime() > endtime) break;
  103.     } while (msg.Event != EVENT_KEYPRESS && !button());
  104.  
  105.     /* wait until the mouse buttons are released */
  106.     while (button());
  107.  
  108.     /* hide the mouse */
  109.     hide();
  110.  
  111.     (*Screen -> SetMode)();
  112.  
  113.     Refresh();
  114.  
  115.     restoremouse();
  116. }
  117.  
  118.  
  119. POOL pascal Pool[] = {
  120.     {"barChart",    Bar,        0,    HANDLER},
  121.     {NULL,          NULL,        0,    0}    };
  122.